package com.seveneight.baijiesteward.ui.main.activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.BaseActivity;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.RankListBean;
import com.seveneight.baijiesteward.http.HttpConfig;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.ui.user.model.PlanRePayInfoModel;
import com.seveneight.baijiesteward.utils.DateUtil;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 计划详情
 */
public class BankPlanInfoActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.execute_info)
    TextView execute_info;
    @BindView(R.id.plan_photo1)
    ImageView plan_photo1;
    @BindView(R.id.plan_photo2)
    ImageView plan_photo2;
    @BindView(R.id.out_bank_name)
    TextView out_bank_name;
    @BindView(R.id.in_bank_name)
    TextView in_bank_name;
    @BindView(R.id.plan_submit_date)
    TextView plan_submit_date;
    @BindView(R.id.plan_info_date)
    TextView plan_info_date;
    @BindView(R.id.consume_money)
    TextView consume_money;
    @BindView(R.id.refund_money)
    TextView refund_money;
    @BindView(R.id.procedure_money)
    TextView procedure_money;
    @BindView(R.id.plan_number)
    TextView plan_number;
    @BindView(R.id.order_number)
    TextView order_number;
    @BindView(R.id.remarks)
    TextView remarks;
    RankListBean bean;
    PlanRePayInfoModel model;
    List<RankListBean> listData;

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_bank_plan_info);
    }

    @Override
    protected void initView() {
        tv_title.setText("计划详情");
        bean= (RankListBean) getIntent().getSerializableExtra("data");
    }

    @Override
    protected void initData() {

        model=new PlanRePayInfoModel();
        Map<String,String> params=new HashMap<>();
        params.put("RepayPlanId",bean.getPlanId());
        model.getBankList(this, jsonFormat.AddCard(params), new MyCallBack<AnyBean>() {
            @Override
            public void onSuccess(AnyBean anyBean) {
                listData= JSON.parseArray(anyBean.getPlanDetailList(),RankListBean.class);
                setViewData(anyBean);
            }

            @Override
            public void onFailed() {

            }
        });
    }
    public void setViewData(AnyBean item){
        plan_submit_date.setText(DateUtil.formatDate(item.getCreatorTime()));
        plan_info_date.setText(DateUtil.formatDate(item.getCreatorTime()));
        consume_money.setText("￥"+item.getRechargeAmount());
        refund_money.setText("￥"+item.getRepayAmount());
        DecimalFormat df=new DecimalFormat("######0.00");
        procedure_money.setText("￥"+df.format((item.getRepayCount()*item.getBrokerage()))+"");
        plan_number.setText(item.getPlanNo());
        order_number.setText(item.getPlanNo());
        if (listData.size()>0){
            order_number.setText(listData.get(0).getOrderNo());
            remarks.setText(listData.get(0).getMessage());
        }
        String outBankName=bean.getOutCardNo();
        out_bank_name.setText(bean.getOutBankName()+"("+outBankName.substring(outBankName.length()- 4)+")");
        String inBankName=bean.getInCardNo();
        in_bank_name.setText(bean.getInBankName()+"("+inBankName.substring(inBankName.length()- 4)+")");
        Glide.with(activity).load(HttpConfig.SOURCE_URL+bean.getOutBankIcon()).into(plan_photo1);
        Glide.with(activity).load(HttpConfig.SOURCE_URL+bean.getInBankIcon()).into(plan_photo2);

        if (bean.getPlanStatus()==4){
            execute_info.setText("执行成功");
        }else if(bean.getPlanStatus()==3){
            execute_info.setText("执行中");
        }else if(bean.getPlanStatus()==2){
            execute_info.setText("执行失败");
        }else if(bean.getPlanStatus()==1){
            execute_info.setText("等待执行");
        }
    }

    @Override
    protected void setListener() {

    }

    @OnClick({R.id.iv_back})
    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
